package jd;

import java.util.Scanner;

public class Test2 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int n = scanner.nextInt();
			int v = scanner.nextInt();
			//第一行表示体积，第二行表示魔幻因子
			int[][] a=new int [n][2];
			for (int i = 0; i < n; i++) {
				a[i][0]= scanner.nextInt();
				a[i][1]= scanner.nextInt();
			}
			getNum(a, v);
		}
		scanner.close();
	}
	//采用动态规划的方法找出体积刚好等于v的编号
	public static void getNum(int[][] a,int v){
		for(int i = 1; i <= v; ++i){
			int cons1 = v - 1;
			int cons2 = v - 2;
			int minConsNum = a[cons1][0];
			if(cons2 >= 0 && a[cons2] [0]< minConsNum)
			{
				minConsNum = a[cons2][0];
			}
			a[i][0]= minConsNum + 1;
			System.out.println(a[i][1]);
			System.out.println(a[i][0]);
		}
	}

}
